package com.xbongbong.saas.service.impl;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.bomproduct.pojo.dto.BomProductDeleteBatchDTO;
import com.xbongbong.pro.bomproduct.pojo.vo.BomProductDeleteBatchVO;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.saas.model.BomProductModel;
import com.xbongbong.saas.service.BomProductService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @author 吴峰
 * @version v1.0
 * @date 2019/3/6 21:36
 * @since v1.0
 */
@Service("bomProductService")
public class BomProductServiceImpl implements BomProductService {

    private static final Logger LOG = LoggerFactory.getLogger(BomProductServiceImpl.class);

    @Resource
    private BomProductModel bomProductModel;

    @Override
    public BomProductDeleteBatchVO deleteBatch(BomProductDeleteBatchDTO bomProductDeleteBatchDTO) throws XbbException {
        BomProductDeleteBatchVO bomProductDeleteBatchVO = new BomProductDeleteBatchVO();
        try {
            List<Long> bomIdIn = bomProductDeleteBatchDTO.getBomIdIn();
            String corpid = bomProductDeleteBatchDTO.getCorpid();
            if (Objects.nonNull(bomIdIn) && !bomIdIn.isEmpty()) {
                bomProductModel.deleteByBomIdIn(bomIdIn, corpid);
            }
        } catch (Exception e) {
            LOG.error("BomProductServiceImpl.deleteBatch 执行出错：", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return bomProductDeleteBatchVO;
    }
}
